let current = {
  test: 0,
  judge: 25,
};

let rules = {
  thresholdEnable: true,
  // 阈值字段
  thresholdField: "judge",
  // 阈值等级
  levels: [
    {
      max: 10,
      min: 0,
      color: "red",
    },
    {
      max: 20,
      min: 10,
      color: "green",
    },
    {
      max: 30,
      min: 20,
      color: "yellow",
    },
  ],
};

const handleThreshold = (currnet, field) => {
  const judgeValue = currnet[field];
  const res = rules.levels.filter((item) => {
    if (judgeValue < item.max && judgeValue >= item.min) {
      return item;
    }
  })[0];
  console.log("需要判断的值", judgeValue);
  console.log("res", res);
  setValue(res);
};

const setValue = (item) => {
  const color = item.color;
  document.querySelector("#box").style.background = color;
};

if (rules.thresholdEnable) {
  handleThreshold(current, rules.thresholdField);
}
